#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stack>

using namespace std;

int calculate(string s) {
    int n = s.size();
    int i = 0;
    char op = '+';
    stack<int> st;

    while (i < n)
    {
        while(s[i] == ' ')
            ++i;
        if (s[i] >= '0' && s[i] <= '9')
        {
            int tmp = 0;
            while (i < n && s[i] >= '0' && s[i] <= '9')
                tmp = tmp * 10 + (s[i++] - '0');
            if (op == '+')   st.push(tmp);
            else if (op == '-')  st.push(-tmp);
            else if (op == '*')  st.top() *= tmp;
            else st.top() /= tmp;
        }
        else
        {
            op = s[i];
            ++i;
        }
    }

    int ret = 0;
    while (!st.empty())
    {
        ret += st.top();
        st.pop();
    }
    return ret;
}
int main()
{
    std::cout << calculate("  30");
	return 0;
}